package com.hnqcgczy.supplier.service.impl;

import com.hnqcgczy.supplier.dao.CompanyDao;
import com.hnqcgczy.supplier.dao.impl.CompanyDaoImpl;
import com.hnqcgczy.supplier.db.MyTransaction;
import com.hnqcgczy.supplier.service.CompanyService;
import com.hnqcgczy.supplier.vo.Company;

import java.sql.SQLException;
import java.util.List;

public class CompanyServiceImpl implements CompanyService {
    //事务提交的方式为自动提交
    private MyTransaction myTransaction = new MyTransaction(true);
    private CompanyDao companyDao = new CompanyDaoImpl(myTransaction);

    @Override
    public boolean addCompany(Company company) throws SQLException {
        return companyDao.addCompany(company) > 0;
    }

    @Override
    public List<Company> queryByLike(Company company, int pageNow, int pageSize) throws SQLException {
        //业务层的分页思路：
        //首页，上一页，下一页，尾页
        int start =pageNow>=1? (pageNow - 1) * pageSize:pageNow*pageSize;
        return companyDao.queryByLike(company, start, pageSize);
    }

    @Override
    public int queryTotals(Company company) throws SQLException {

        return companyDao.queryTotals(company);
    }

    @Override
    public Company findOne(Integer companyId) throws SQLException {
        return companyDao.findOne(companyId);
    }

    @Override
    public boolean update(Company company) throws SQLException {
        return companyDao.update(company) > 0;
    }

    @Override
    public boolean delete(Integer companyId) throws SQLException {
        return companyDao.delete(companyId) > 0;
    }
}
